﻿Imports System.Data.OleDb
Imports DTO
Public Class DiemMonHocDAO
    'kiem tra xem da ton tai 
    Public Function KiemTra(ByVal DiemMonHoc As DiemMonHocDTO) As Integer
        Dim sql As String = "SELECT COUNT(*) FROM DIEMMONHOC WHERE"
        sql += " MALOP = " + DiemMonHoc.MaLop.ToString
        sql += " AND MAMON = " + DiemMonHoc.MaMon.ToString
        sql += " AND MAHOCKY = " + DiemMonHoc.HocKy.ToString
        Dim cn As OleDbConnection = DataProvider.ConnectDB()
        Dim cm As New OleDbCommand(sql, cn)
        Dim kq As Integer = cm.ExecuteScalar()
        Return kq
    End Function

    Public Function LayMaDiemMon(ByVal DiemMonHoc As DiemMonHocDTO) As Integer
        Dim sql As String = "SELECT MADIEMMONHOC FROM DIEMMONHOC WHERE"
        sql += " MALOP = " + DiemMonHoc.MaLop.ToString
        sql += " AND MAMON = " + DiemMonHoc.MaMon.ToString
        sql += " AND MAHOCKY = " + DiemMonHoc.HocKy.ToString
        Dim cn As OleDbConnection = DataProvider.ConnectDB()
        Dim cm As New OleDbCommand(sql, cn)
        Dim kq As Integer = cm.ExecuteScalar()
        Return kq
    End Function

    Public Function ThemMaDiemMon(ByVal DiemMonHoc As DiemMonHocDTO)
        Dim sql As String = "INSERT INTO DIEMMONHOC(MALOP,MAMON,MAHOCKY) VALUES("
        sql += " " + DiemMonHoc.MaLop.ToString
        sql += "," + DiemMonHoc.MaMon.ToString
        sql += "," + DiemMonHoc.HocKy.ToString
        sql += ")"
        Dim cn As OleDbConnection = DataProvider.ConnectDB()
        Dim cm As New OleDbCommand(sql, cn)
        Dim kq As Integer = cm.ExecuteNonQuery()
        Return kq
    End Function
End Class
